Repository navigation
feat(cloudflare): add cloudflare pack for Workers and Pages deploys - #656
Merged
Merged
Conversation
An independent pack (ADR-0069), 0.1.0 preview, unpublished: deployment.worker and deployment.pages on the delivery pack's deployment.base, and a Worker's D1, KV, R2, queue and rate limiting bindings. Generators write wrangler.jsonc (every env block in full, each fact commented with its model node, valid against Wrangler 4.168.0's schema), a wrangler wrapper that runs as the environment's narrow token with the global-key variables unset and a pinned wrangler, deploy, secret sync and doctor scripts, and the facts no file holds. Three success fixtures modelled on adopters' hand-written Cloudflare configuration, with golden output and a fact-by-fact coverage test; five load-error fixtures. TypeScript port only. Core is unchanged.
# Conflicts: # packs/README.md
…, delivery constants - deploy.sh sets a build-time default with a shell-quoted value only when the variable is unset, so a value holding } or quotes exports as written. - Refuse @main, @WorkersDev or assets set in some environments and not others: Wrangler would fill the gap from the top level. - An empty value.literal on a build-time setting overrides its @default, as it does for a runtime var. - Read build, runtime and output attributes through the delivery pack's constants. - Name CLOUDFLARE_API_TOKEN apart from the global-key variables in the runner's header and the README.
…red test fixtures - Read the build and runtime processes through the delivery pack's readBuild and readProcesses; take MANAGED_BY_EXTERNAL from the systems pack. - One helper writes each binding list and its comment; the JSONC writer refuses a key written twice, so @extra can never shadow a generated key. - No empty-string sentinel for an unresolved top level; the inherited-key check no longer waits on it. - resolvePaths fills every path; header is module-private. - Tests load and emit each fixture once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
packs/cloudflarepack (@metaobjectsdev/pack-cloudflare, 0.1.0, preview, unpublished). It registersdeployment.worker(Worker, with or without static assets),deployment.pages, and the Worker'scloudflare.d1,.kv,.r2,.queueand.ratelimitbindings, on top of thedeliveryandconfigpacks.wrangler.jsonc(top-level plus oneenvblock per other environment),deploy/cloudflare/wrangler.sh(wrangler run as the deployment's narrow vault token),deploy.sh,sync-secrets.sh,doctor.shandunexpressed.md. The generators write files only; the scripts talk to Cloudflare and the vault when run.CHANGELOG.md,README.md, thepacks/README.mdindex row, four golden-output conformance fixtures, five load-error fixtures, and TypeScript tests (coverage, emit, model, script behaviour against stubbedkeys-axiandnpx). Also adds the workspace entry inbun.lock.Validation
Risk Assessment
✅ Low: The latest fix rounds (empty deploy token refusal, wranglerVersion option removal, Pages secret-scope refusal narrowed to project and environment) are correct and covered by script-executing tests. I found no defects. The pack is unpublished and preview, and the change touches no core code.
Testing
Baseline
scripts/ci-local.sh --affected --strict-toolchainsalready passed; broad regression is not rerun here. Focusedbun testof the cloudflare pack passed 55/55. Three live scenarios were driven: (1) the generated Worker runner deploys with only the vault token and pinned Wrangler, including the same-named token variant; (2) adversarial empty, absent and same-named empty deploy tokens are refused before any Wrangler call; (3) generator boundaries for Pages: two projects accepted, a secret as value node refused. All three passed with evidence transcripts. A realwrangler deployagainst a Cloudflare account was not run (no credentials, network to Cloudflare out of scope), so it is untested. Evidence written to the evidence directory: cf-wrangler-runner-transcript.txt, cf-generator-run.log, cf-generated-wrangler.sh.Evidence: Live Worker runner and adversarial token transcript
Evidence: Generator run: Pages two-project accepted, secret-as-value refused
Evidence: Generated wrangler.sh from the Worker fixture
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - all findings resolved (3 fix rounds)
Every finding was fixed in the pipeline's fix rounds; none remain open.
packs/cloudflare/typescript/src/files.ts- Pages secret sync and doctor now target the right Pages environment (production or preview, from the project's production branch) with--env; a model that cannot tell is refused, naming the node (CF-1).packs/cloudflare/typescript/src/model.ts- a@secret @phase: buildsetting and a build-phasevalue.refare refused at generation, naming the node and setting, instead of silently dropped;unexpressed.mdis accurate for the no-build-command case (CF-2).packs/cloudflare/typescript/src/model.ts-value.ref @pathis appended to apublicUrlreference (CF-3).packs/cloudflare/typescript/src/model.ts- inheritable@extrakeys are held to the every-environment-or-none rule (CF-4).packs/cloudflare/typescript/src/files.ts-@tokenSecretis quoted indoctor.sh(CF-5).packs/cloudflare/typescript/src/model.ts-unexpressed.mdlists a Worker's@branchand only runtime-phase Pages values (CF-6).packs/cloudflare/typescript/src/files.ts- generated heading grammar per kind (CF-7).acmeplaceholder vault project, scope and token names (CF-8).wrangler.shkeeps the vault token when the entry is namedCLOUDFLARE_API_TOKENand refuses an empty or missing token, so it never falls back to a logged-in Wrangler session (CF-12, CF-14).pages secret listoutput (CF-15).@tokenVaultis absent (CF-18).wranglerVersiongenerator option is removed; the runner reads the pinned constant, and theWRANGLER_VERSIONenvironment override stays (CF-19).editFixture; README fixture count corrected (CF-10, CF-13).✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --affected --strict-toolchainsbun testin packs/cloudflare/typescript (55 pass, 0 fail), focused pack suiteGenerator driver (bun, real emit from packs/cloudflare/typescript/test/model.ts) on fixture cloudflare-worker-cron-ratelimits: wrote deploy/cloudflare/{wrangler.sh,deploy.sh,doctor.sh,sync-secrets.sh,unexpressed.md} and wrangler.jsonc into a scratch siteLive run of generatedbash deploy/cloudflare/wrangler.sh production deploy --config wrangler.jsoncwith stub keys-axi and npx on PATH and synthetic vault values: exit 0, npx ranwrangler@4.168.0 deploy, CLOUDFLARE_API_TOKEN=value-of-ACME_WORKERS_TOKEN, no CLOUDFLARE_EMAIL/CLOUDFLARE_API_KEYLive same-named variant (@tokenSecret CLOUDFLARE_API_TOKEN) with shell token set: exit 0, npx token is the vault valueLive adversarial runs: STUB_EMPTY=ACME_WORKERS_TOKEN, STUB_MISSING=ACME_WORKERS_TOKEN, and empty same-named token: exit 1 each, message 'the deploy token ... is empty or is not in the vault scope', npx never invokedGenerator refusal/acceptance on cloudflare-pages-secrets with editFixture: two Pages projects (help-site and help-site-staging) sharing Pages production accepted, sync-secrets staging line correct; @secret setting as value.literal refused with the expected messageVerified Pages doctor secret-list parser against published wrangler@4.168.0 dist (pagesSecretListCommand prints- NAME: Value Encrypted), via npm pack into scratchCleanup: scratch dirs removed, worktree clean (git status empty)✅ **Document** - passed (1 resolved note)
docs/recipes/cloudflare-workers.md:200- Out-of-scope follow-up: the recipe's hand-written wrangler.toml section overlaps what packs/cloudflare now generates (wrangler.jsonc, deploy scripts). Still accurate, so left unchanged. When the cloudflare pack leaves preview, reduce that section to a pointer to packs/cloudflare/README.md.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.